//
//  BLClothRecicalViewController.m
//  blanket
//
//  Created by Mac on 2017/12/6.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLClothRecicalViewController.h"
#import "BLTextFieldControl.h"
#import "STTextView.h"
#import "BLClothRecicalPresentViewController.h"
@interface BLClothRecicalViewController ()
@property(nonatomic, strong) BLTextFieldControl                     *chuangdanControl;
@property(nonatomic, strong) BLTextFieldControl                     *beitaoControl;
@property(nonatomic, strong) BLTextFieldControl                     *zhengtaoControl;
@property(nonatomic, strong) BLTextFieldControl                     *yujinControl;
@property(nonatomic, strong) BLTextFieldControl                     *mianjinControl;
@property(nonatomic, strong) STTextView                     *textView;
@end

@implementation BLClothRecicalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"布草回收";
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self configSubView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    header.backgroundColor = [UIColor whiteColor];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(30, 20, UIScreenWidth - 60, 30)
                                                     text:@"请输入需要回收的布草数量"
                                                textColor:BL_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:titleLable];
    CGFloat textWith = (UIScreenWidth - 90)/2;
    self.chuangdanControl = [[BLTextFieldControl alloc] initWithLineFrame:CGRectMake(30, titleLable.bottom, textWith, 20) leftTitle:@"床单:" rightTitle:@""];
    [header addSubview:self.chuangdanControl];
    self.beitaoControl = [[BLTextFieldControl alloc] initWithLineFrame:CGRectMake(30 + _chuangdanControl.right, titleLable.bottom, textWith, 20) leftTitle:@"被套:" rightTitle:@""];
    [header addSubview:self.beitaoControl];
    
    self.zhengtaoControl = [[BLTextFieldControl alloc] initWithLineFrame:CGRectMake(30, _chuangdanControl.bottom + 20, textWith, 20) leftTitle:@"枕套:" rightTitle:@""];
    [header addSubview:self.zhengtaoControl];
    
    self.yujinControl = [[BLTextFieldControl alloc] initWithLineFrame:CGRectMake(30 + _zhengtaoControl.right, _chuangdanControl.bottom + 20, textWith, 20) leftTitle:@"浴巾:" rightTitle:@""];
    [header addSubview:self.yujinControl];
    
    self.mianjinControl = [[BLTextFieldControl alloc] initWithLineFrame:CGRectMake(30 , _yujinControl.bottom + 20, textWith, 20) leftTitle:@"面巾:" rightTitle:@""];
    [header addSubview:self.mianjinControl];
    
    
    self.textView = [[STTextView alloc] initWithFrame:CGRectMake(30, _mianjinControl.bottom + 20, UIScreenWidth - 60, 125)];
    self.textView.backgroundColor = BL_backgroundColor;
    self.textView.placeholder = @"备注:";
    self.textView.placeholderColor = BL_secendTextColor;
    [header addSubview:self.textView];
    
    __weak typeof(self) weakSelf =  self;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(25, self.textView.bottom + 60, UIScreenWidth - 50, 44)
                                                        title:@"提交"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:5
                                              backgroundColor:BL_BlueBackGroundColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedCommitButton];
    }];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:confimButton];
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, confimButton.bottom + 50, 80, 80)];
    imageView.centerX = UIScreenWidth / 2;
    imageView.image = [UIImage imageNamed:@"底图logo"];
    [header addSubview:imageView];
    
    header.height = imageView.bottom ;
    self.tableView.tableHeaderView = header;
}
- (void)onSelectedCommitButton{


    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    if (!self.chuangdanControl.textFiled.text.length) {
        [dic setObject:@"0" forKey:@"bed"];
//        return;
//        [SVProgressHUD showErrorWithStatus:@"您还未输入床单"];
//        return;
    }else{
        [dic setObject:self.chuangdanControl.textFiled.text forKey:@"bed"];
    }
    
    if (!self.beitaoControl.textFiled.text.length) {
        [dic setObject:@"0" forKey:@"quilt"];
//        return;
//        [SVProgressHUD showErrorWithStatus:@"您还未输入被套"];
//        return;
    }else{
        [dic setObject:self.beitaoControl.textFiled.text forKey:@"quilt"];
    }
    
    if (!self.zhengtaoControl.textFiled.text.length) {
        [dic setObject:@"0" forKey:@"towel"];
//        return;
//        [SVProgressHUD showErrorWithStatus:@"您还未输入枕套"];
//        return;
    }else{
        [dic setObject:self.zhengtaoControl.textFiled.text forKey:@"towel"];
    }
    
    if (!self.yujinControl.textFiled.text.length) {
        [dic setObject:@"0" forKey:@"tick"];
//        return;
//        [SVProgressHUD showErrorWithStatus:@"您还未输入浴巾"];
//        return;
    }else{
        [dic setObject:self.yujinControl.textFiled.text forKey:@"tick"];
    }
    
    
    if (!self.mianjinControl.textFiled.text.length) {
        [dic setObject:@"0" forKey:@"face_cloth"];
//        return;
//        [SVProgressHUD showErrorWithStatus:@"您还未输入面巾"];
//        return;
    }else{
        [dic setObject:self.mianjinControl.textFiled.text forKey:@"face_cloth"];
    }
    
    if (!self.textView.text.length) {
        [SVProgressHUD showErrorWithStatus:@"您还未输入备注"];
        return;
    }else{
        [dic setObject:self.textView.text forKey:@"content"];
    }
    BLClothRecicalPresentViewController * vc = [BLClothRecicalPresentViewController new];
    vc.dic = dic;
    [self presentViewController:vc animated:NO completion:nil];
}
@end
